import java.rmi.server.UID
import java.security.*

public class Invite {
	User creator
	String inviteCode
	User invited
	Date dateCreated
	Date lastUpdated

	static constraints = {
		creator(blank:false)
		inviteCode(blank:false,size:1..80,unique:true)
	}

	void createInviteCode() {
		// @todo replace deadbeef with some random hex digits
        def hexUID = new UID().toString().replaceAll(/[^a-z0-9]/, '') + 'deadbeefdeadbeef'
        // To convert to bytes for encoding as base62 we need to make sure length is even
        if (hexUID.size() % 2) {
            hexUID += '0'
        }
		inviteCode = hexUID.decodeHex().encodeAsBase62()
	}
}
